#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int n = 0;
    scanf("%d", &n);
    int* num = (int*)malloc(sizeof(int) * n);
    for(int i = 0; i < n; i++)
    {
        int a = 0, b = 0, count = 1, coin = 0, kong = 0, j = 0, flag1 = 1, flag2 = 1;
        char* ret = NULL;
        char arr[100006] = {0};
        char* sep = "1";
        scanf("%d%d", &a, &b);
        getchar();
        while((arr[j] = getchar()) != '\n')
        {
            if(arr[j] == '1')
            flag1 = 0;
            if(arr[j] == '0')
            flag2 = 0;
            j++;
        }
        if(flag1)
        {
            num[i] = 0;
            continue;
        }
        if(flag2)
        {
            num[i] = a;
            continue;
        }
        char* e = arr;
        char* f = arr + j - 1;
        while(*e == '0'&&e <= f){e++;};
        while(*f == '0'&&e <= f){f--;};
        *f = '\0';
        for(ret = strtok(e, sep); ret != NULL; ret = strtok(NULL, sep))
        {
            int len = strlen(ret);
            if(len*b < a)
            {
                coin += len*b;
            }
            else
            {
                kong++;
            }
        }
        coin += (kong+1) * a;
        num[i] = coin;
    }
    for(int i = 0; i < n; i++)
    {
        printf("%d\n", num[i]);
    }
    free(num);
    return 0;
}